package com.oracle.coherence.patterns.security.management;

import com.oracle.coherence.patterns.security.accesscontrol.Action;

public enum JmxAction implements Action {
    NONE(0x00000000, "none"),   // 0000 0000 0000 0000 0000 0000 0000 0000
    ALL(-1, "all"),             // 1111 1111 1111 1111 1111 1111 1111 1111
    CONNECT(0x00000001),        // 0000 0000 0000 0000 0000 0000 0000 0001
    ;

    private int flagValue;
    private String name;

    JmxAction(int flagValue) {
        this(flagValue, null);
    }

    JmxAction(int flagValue, String name) {
        this.flagValue = flagValue;
        this.name = name;
    }

    @Override
    public int getFlagValue() {
        return flagValue;
    }

    @Override
    public String getActionName() {
        return (name != null) ? name : this.toString().toLowerCase();
    }

    @Override
    public Action fromName(String name) {
        for (JmxAction action : JmxAction.values()) {
            if (action.getActionName().equalsIgnoreCase(name)) {
                return action;
            }
        }

        throw new IllegalArgumentException("name [" + name + "] does not match any JmxAction name");
    }

    @Override
    public Action[] actionList() {
        return JmxAction.values();
    }

}